﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using BCCommon.TMS.FreightEnums;
using BCCommon.TMS.Order;
using BCEntity.TMS.FreightConfiguration;

namespace BCData.TMS.FreightConfiguration
{
    /// <summary>
    /// 运费配置数据库访问
    /// </summary>
    public interface IFreightConfigurationData
    {
        /// <summary>
        /// 检查运费配置是否存在
        /// </summary>
        /// <param name="vehicleTypeId">车型Id</param>
        /// <param name="vehicleCategoryReferenceId">车辆分类Id</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">城市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="sourceType">订单来源</param>
        /// <param name="freightType">物流类型</param>
        /// <returns></returns>
        Task<int> CheckFreightConfigurationExists(int vehicleTypeId, int vehicleCategoryReferenceId, string provinceCode, string cityCode, string countyCode, OrderSourceType sourceType, FreightType freightType);

        /// <summary>
        /// 检查运费配置是否存在
        /// </summary>
        /// <param name="freightConfigId"></param>
        /// <returns></returns>
        Task<int> CheckFreightConfigurationExists(int freightConfigId);

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entitys"></param>
        /// <returns></returns>
        Task<int> InsertAllAsync(List<FreightConfigurationEntity> entitys);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(FreightConfigurationEntity entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="freightConfigurationId">运费配置id</param>
        /// <returns></returns>
        Task<int> DeleteAsync(int freightConfigurationId);

        /// <summary>
        /// 通过id获取运费详情
        /// </summary>
        /// <param name="freightConfigurationId">运费配置id</param>
        /// <returns></returns>
        Task<FreightConfigurationExpandEntity> GetByIdAsync(int freightConfigurationId);

        #region 获取运费

        /// <summary>
        /// 获取运费
        /// </summary>
        /// <param name="vehicleTypeId">车型Id</param>
        /// <param name="VehicleCategoryReferenceId">车辆分类映射Id</param>
        /// <param name="provinceId">起始地省份编码</param>
        /// <param name="communityId">起始地城市编码</param>
        /// <param name="countyId">起始地区县编码</param>
        /// <param name="sourceType">订单来源</param>
        /// <param name="freightType">物流类型</param>
        /// <returns></returns>
        Task<FreightConfigurationEntity> GetFreight(int? vehicleTypeId, int? VehicleCategoryReferenceId, string provinceId, string communityId, string countyId, OrderSourceType? sourceType, FreightType? freightType);

        #endregion 获取运费

        /// <summary>
        /// 运费配置分页列表
        /// </summary>
        /// <returns></returns>
        Task<(IEnumerable<FreightConfigurationExpandEntity>, int)> GetAsync(long? agentRecordId, FreightConfigurationViewEntity viewEntity);

        /// <summary>
        /// 查询运费列表
        /// </summary>
        /// <param name="viewEntity"></param>
        /// <returns></returns>
        Task<(IEnumerable<FreightConfigurationExpandEntity>, int dataCount)> QeuryAsync(FreightConfigurationViewEntity viewEntity);

        /// <summary>
        /// 新增整车运费配置
        /// </summary>
        /// <param name="freightEntity">运费配置</param>
        /// <returns></returns>
        Task<int> InsertManyRowAsync(FreightConfigurationEntity freightEntity);

        /// <summary>
        /// 获取已存在运费配置的区县编码
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<string>> GetCountyCodeList();

        /// <summary>
        /// 新增修复不存在运费配置的区县编码
        /// </summary>
        /// <param name="tempCountyCode">需要修复的区县编码</param>
        /// <param name="countyCode">已存在的运费配置的区县编码</param>
        /// <returns></returns>
        Task<int> InsertReparir(string tempCountyCode, string countyCode);

        /// <summary>
        /// 获取已存在运费配置的车型和车辆分类ID
        /// </summary>
        /// <returns></returns>
        Task<IDictionary<int, int>> GetVehicleTypeIdAndReferenceIdList();

        /// <summary>
        /// 新增修复不存在运费配置的车型和车辆分类
        /// </summary>
        /// <param name="keyValuePair">已存在车型车辆分类ID</param>
        /// <param name="vehicleCategoryReferenceId">车辆分类ID</param>
        /// <param name="vehicleTypeId">车型ID</param>
        /// <returns></returns>
        Task<int> InsertReparir(KeyValuePair<int, int> keyValuePair, int vehicleCategoryReferenceId, int vehicleTypeId);

        /// <summary>
        /// <param name="agentRecordId">代理商ID</param>
        /// <param name="provinceCode">省编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区/县编码</param>
        /// <param name="vehicleTypeId">车辆类型id</param>
        /// <param name="sourceType">订单来源</param>
        /// <param name="freightType">物流类型</param>
        /// <returns></returns>
        Task<IEnumerable<FreightConfigurationEntity>> GetList(long? agentRecordId, string provinceCode, string cityCode, string countyCode, int? vehicleTypeId, OrderSourceType? sourceType, FreightType? freightType);
    }
}